<?php
//开启session

        


		$id = !empty($_GET['id'])?$_GET['id']:'';

		if(!empty($_POST)){


       if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

         $id = $_POST['id'];
         $val = $_POST['val'];
         $filed = $_POST['filed'];


    // echo  $_rows = edit(`admin`,$_POST);
     // $_row = edit('admin',$id,$_POST);
    $sql = "update `admin` set `$filed`='$val' where`id`=$id";
        //编写执行语句
          mysqli_query($link,$sql);
           // 获取影响的行数
          echo $_rows=mysqli_affected_rows($link);

        die;
       }
  


                //$_POST的所有数据存储在临时变量中
                  // $username=$_POST['username'];
                  // $password=$_POST['password'];
                  // $age=$_POST['age'];
                  // $sex=$_POST['sex'];


  $_rows = edit('admin',$id,$_POST);

//如果$_rows>0说明成功
if ($_rows>0) {
    echo '<script> alert ("管理员编辑成功");location.href="index.php?c=admin&a=list&admin=1";</script>';die;
       
}else{

    echo '<script> alert ("管理员编辑失败");history.go(-1);</script>';
        die;
}


}

$data = getSelectByOne('admin',"id=$id");


// $sql="select * from `admin` where `id`=$id";


// $result = mysqli_query($link,$sql);

// $data = mysqli_fetch_assoc($result);

// print_r($data);die;

//链接语句
include (VIEW_PATH.$admin.'layout.html');
?>

